package org.projects.graduates.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Table;

import com.dayatang.domain.AbstractEntity;

@Entity
@Table(name = "roles_")
public class Role extends AbstractEntity {

	private static final long serialVersionUID = 6177279454794207607L;

	@Column(unique = true,name="role_name")
	private String name;

	@ElementCollection(fetch = FetchType.EAGER)
	@CollectionTable(name = "roles_permissions", joinColumns = @JoinColumn(name = "role_id"))
	@Column(name = "permission_stringName")
	private Set<String> permissions = new HashSet<String>();

	public boolean equals(Object obj) {
		if(obj instanceof Role){
			return ((Role)obj).getName().equals(this.getName());
		}
		return false;
	}

	public int hashCode() {
		return this.name.hashCode();
	}

	@Override
	public String toString() {
		return name + "  " + permissions;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<String> getPermissions() {
		return permissions;
	}

	public void setPermissions(Set<String> permissions) {
		this.permissions = permissions;
	}

}
